package com.xiaodimall.beforesys.controller;

import com.xiaodimall.beforesys.pojo.User;
import com.xiaodimall.beforesys.service.UserService;
import com.xiaodimall.utils.Result;
import com.xiaodimall.utils.ResultGenerator;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author wyc
 * @description
 * @ClassName UserInfoController
 * @date 2022/11/30 17:54
 */
@Controller
public class UserInfoController {

    //注入用户业务层模块
    @Resource
    UserService userService;

    @ApiOperation(value = "跳转个人中心页面")
    @GetMapping("/personal")
    public String personalPage() {
        return "mall/personal";
    }


    @ApiOperation(value = "修改用户信息和地址")
    @PostMapping("/personal/updateInfo")
    @ResponseBody
    public Result updateInfo(@RequestBody User mallUser, HttpSession httpSession) {
        //调用业务层修改信息方法
        User userInfo = userService.updateUserInfo(mallUser,httpSession);
        if (userInfo == null) {
            return ResultGenerator.genFailResult("修改失败");
        } else {
            //返回成功
            return ResultGenerator.genSuccessResult();
        }
    }


}
